package com.caimiao.miao.page.master.system.bluetooth;

import android.content.Context;

import com.caimiao.miao.library.bluetooth.BTDevice;
import com.caimiao.miao.library.bluetooth.BluetoothControl;

import java.util.List;

import io.reactivex.Observable;

public class BluetoothModel implements IBluetoothContact.Model {
    private BluetoothControl mBluetoothControl;

    @Override
    public boolean initBluetooth(Context context) {
        mBluetoothControl = new BluetoothControl(context);
        return mBluetoothControl.enableBluetooth();
    }

    @Override
    public void startDiscovery() {
        mBluetoothControl.startDiscovery();
    }

    @Override
    public List<BTDevice> getBondedDevices() {
        return mBluetoothControl.getBondedDevices();
    }

    @Override
    public void unregisterBluetoothReceiver() {
        mBluetoothControl.close();
    }

    @Override
    public void connect(BTDevice device) {
        mBluetoothControl.connect(device);
    }

    @Override
    public Observable<BTDevice> getDevices() {
        return mBluetoothControl.getDevices();
    }

    @Override
    public Observable<String> read() {
        return mBluetoothControl.read(true);
    }

    @Override
    public void write(byte[] value) {
        mBluetoothControl.write(value);
    }
}
